#!/bin/bash
#启动参数
JAVA_OPTIONS=" -Xms256m -Xmx1024m -Dhudson.util.ProcessTree.disable=true "
#nohup java $JAVA_OPTIONS -jar /opt/jenkins_home/jenkins.war > /opt/logs/jenkins/jenkins.log 2>&1 &
case $1 in
#启动服务
start)
    echo "jenkins is starting"
    nohup java $JAVA_OPTIONS -jar /opt/jenkins_home/jenkins.war --httpPort=8090 --httpListenAddress=127.0.0.1 > /opt/logs/jenkins/jenkins.log 2>&1 &
;;
stop)
#停止服务
    ps -elf |grep jenkins|grep -v grep|awk '{print $4}'|xargs kill -9
;;
restart)
#重启服务$0为脚本本身
    pid=`ps -elf |grep jenkins|grep -v $0|grep -v grep|awk '{print $4}'`
    echo $pid
    kill -9 $pid
    sleep 2
    echo "ready to start"
    nohup java $JAVA_OPTIONS -jar /opt/jenkins_home/jenkins.war --httpPort=8090 --httpListenAddress=127.0.0.1 > /opt/logs/jenkins/jenkins.log 2>&1 &
;;
*)
   echo "please input start|stop|restart"
;;
esac
